package com.example.ioc.factorybean;

import org.springframework.beans.factory.FactoryBean;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * Description
 *
 * @author tcwong
 * @date 2022/7/24
 * Since 1.8
 */
public class SoaServiceFactory implements FactoryBean<Object>, InvocationHandler {
    private Class clazz;

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        return "proxy@"+clazz.getSimpleName();
    }

    @Override
    public Object getObject() throws Exception {
        return Proxy.newProxyInstance(clazz.getClassLoader(),new Class[]{clazz},this);
    }

    @Override
    public Class<?> getObjectType() {
        return clazz;
    }

    public void setClazz(Class clazz) {
        this.clazz = clazz;
    }
}
